#!/bin/bash

if [ ! -e '.env' ]
then
  echo '请先设置 .env 配置文件'
  exit 1
fi

# 上级目录
DOCKER_WORK_PATH=$(dirname $(cd `dirname $0`; pwd))

source "$DOCKER_WORK_PATH/.phpdocker/Docker.sh"

# -------------------------------------------------------------------------------------
# 配置变量 START
# -------------------------------------------------------------------------------------
# PHP版本
DOCKER_PHP_VERSION=$(loadEnv 'DOCKER_PHP_VERSION' '8.0')-fpm-alpine
# 镜像名称
DOCKER_IMAGE_NAME="${DOCKER_PHP_VERSION}-run"
# 运行容器名称（多个项目时必须设置唯一）
DOCKER_NAME=$(loadEnv 'DOCKER_NAME' 'php-project-01')
# 容器内工作目录
DOCKER_WORKSPACE='/workspace/php'
# 绑定到主机的端口
LOCAL_PORT=$(loadEnv 'LOCAL_PORT' 80)
# 执行操作
ACTION=$1
# -------------------------------------------------------------------------------------
# 配置变量 END
# -------------------------------------------------------------------------------------

case $ACTION in
    start)
        checkNetwork
        checkPort
        start
        RunNginx
        exit 0
    ;;
    restart)
        checkNetwork
        checkPort
        stop
        start
        RunNginx
        exit 0
    ;;
    stop)
       stop
       exit 0
    ;;
    remove)
        remove
        exit 0
    ;;
    exec)
        exec
        exit 0
    ;;
    export)
      export
      exit 0
    ;;
    import)
      import
      exit 0
    ;;
    help)
        help
        exit 0
    ;;
    *)
        echo "Unknown option."
        help
        exit 0
    ;;
esac